#!/usr/bin/python
# -*- coding:UTF-8 -*-

import md5
import params

def generateSignature(params,secret):
    r=[]
    params.sort()
    params.append(secret)
    txt=''.join(params)
    m=md5.new()
    txt=unicode(txt)
    #for s in txt:
        #print ord(s),
    #print
    m.update(txt)
    txt=m.digest()
    for t in txt:
        r.append(hex((ord(t) & 0xf0)>>4)[2])
        r.append(hex(ord(t) & 0x0f)[2])
    return ''.join(r)

def convert(p):
    result=[]
    for k in p.keys():
        result.append(params.stripSignaturePrefix(k)+"="+str(p[k]))
    return result

if __name__=="__main__":
    p=['def','abc','x','汉字']
    str=generateSignature(p, 'secret')
    print str